package com.yidu.BusinessParameters.service.impl;

import com.yidu.BusinessParameters.entity.MarketEntity;
import com.yidu.BusinessParameters.mapper.MarketMapper;
import com.yidu.BusinessParameters.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MarketServiceImpl implements MarketService {

    @Autowired
    private MarketMapper marketMapper;

    @Override
    public List<MarketEntity> marketSelect() {
        return marketMapper.marketSelect();
    }

    @Override
    public List<MarketEntity> marketSelects(int page, int limit, MarketEntity marketEntity) {
        Map map = new HashMap<>();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("moneyAllocate",strWriter(marketEntity));
        List<MarketEntity> marketEntityList = marketMapper.marketSelects(map);
        return marketEntityList;
    }

    @Override
    public int marketinsert(MarketEntity marketEntity) {
        return marketMapper.marketinsert(marketEntity);
    }

    @Override
    public int marketdelete(String marketId) {
        return marketMapper.marketdelete(marketId);
    }

    @Override
    public int marketupdate(MarketEntity marketEntity) {
        return marketMapper.marketupdate(marketEntity);
    }

    @Override
    public int two() {
        return marketMapper.two();
    }

    public String strWriter(MarketEntity marketEntity){
        StringBuffer buffer = new StringBuffer("");
        if (marketEntity.getSecurityId() != null && !marketEntity.getSecurityId().equals("")){
            buffer.append(" and m.securityId like  '%"+marketEntity.getSecurityId()+"%'");
        } if (marketEntity.getInputDate() != null && !marketEntity.getInputDate().equals("")){
            buffer.append(" and inputDate ='"+marketEntity.getInputDate()+"'");
        }
        System.out.println("进入strWriter"+buffer.toString());
        return buffer.toString();
    }
}
